package com.sc.passbook.service;

import com.alibaba.fastjson.JSON;
import com.sc.passbook.constant.Constant;
import com.sc.passbook.vo.PassTemplate;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.kafka.support.KafkaHeaders;
import org.springframework.messaging.handler.annotation.Header;
import org.springframework.messaging.handler.annotation.Payload;
import org.springframework.stereotype.Component;

/**
 * @author sc
 * Created on  2018/9/1
 */
@Component
@Slf4j
public class ConsumePassTemplate {

    @Autowired
    private IHbaseService hbaseService;


    @KafkaListener(topics = {Constant.TEMPLATE_TOPIC}  )
    public void receive(@Payload String template,
                        @Header(KafkaHeaders.RECEIVED_MESSAGE_KEY)String key,
                        @Header(KafkaHeaders.RECEIVED_PARTITION_ID) int partition,
                        @Header(KafkaHeaders.RECEIVED_TOPIC) String topic){
        log.info(template);
        PassTemplate pt = JSON.parseObject(template,PassTemplate.class);
        hbaseService.dropPassTemplateToHbase(pt);
    }
}
